﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
#if !NETCOREAPP
using System.Web;
using System.Web.Mvc;
using System.Web.WebPages;
    using System.Web.Mvc.Html;

#endif

#if NETCOREAPP
using Microsoft.AspNetCore.Mvc.Rendering;
using Kugar.Core.Web;
#endif
using Kugar.Core.ExtMethod;
using Kugar.MVC.MobileUI.WeUI.Helpers;

namespace Kugar.MVC.MobileUI.WeUI.PageControls.PageForm
{
    public class PageForm_Link:PageForm_FieldBase
    {
        private string _href = "";
        private string _onclickscript = null;
        private string _value = "";

        public PageForm_Link(ViewContext viewContext) : base(viewContext)
        {
            _attrs.Class("mobileui-form-field weui-cell_link");
        }

        /// <summary>
        /// 整个字段的跳转链接
        /// </summary>
        /// <param name="hrefUrl"></param>
        /// <returns></returns>
        public PageForm_Link Href(string hrefUrl)
        {
            _href = hrefUrl;

            return this;
        }

        /// <summary>
        /// 点击整个字段时,触发事件
        /// </summary>
        /// <param name="script"></param>
        /// <returns></returns>
        public PageForm_Link OnClickScript(string script)
        {
            _onclickscript = script;

            return this;
        }

        public PageForm_Link Value(string value)
        {
            _value = value;

            return this;
        }
        
        protected override void BeginRender()
        {
            base.BeginRender();

            if (!string.IsNullOrWhiteSpace(_href))
            {
                this.Data("data-goto", _href);
            }

            if (!string.IsNullOrWhiteSpace(_onclickscript))
            {
                this.Attributes.SetOrReplaceAttr("onclick",_onclickscript);
            }
        }

        protected override void RenderBody()
        {
            ViewContext.Writer.WriteLine($"<label  class=\"value\">{_value}</label>");
        }
    }
}